Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n: handle string placeholder collisions #14432

Merged
merged 2 commits into from
Oct 6, 2022
Merged

Conversation

brendankenny
Copy link
Member

There was a collision error when importing the latest strings to TC due to a difference in placeholders in core/audits/accessibility/aria-meter-name.js | description and core/audits/accessibility/aria-tooltip-name.js | description.

Chain of events:

With this PR, to count as "allowed" collisions, placeholders must also be exact matches, or collect-strings will suggest changing the string description to be a fixable collision.

I also stepped through a bunch of the TC code to try to figure out collisions once and for all(tm) and documented it in the i18n readme for future reference.

@brendankenny brendankenny requested a review from a team as a code owner October 5, 2022 18:18
@brendankenny brendankenny requested review from connorjclark and removed request for a team October 5, 2022 18:18
@@ -211,6 +211,23 @@ CTC is a name that is distinct and identifies this as the Chrome translation for
}
```

### Collisions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

history has shown we pretty reliably forget this information over time, so please give any feedback on ambiguity so we can clear it up now :)

* @param {(element: T) => U} callback
* @return {Map<U, Array<T>>}
*/
function arrayGroupToMap(elements, callback) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to do this twice (nested) and was getting kind of gross. It's a nice API (for Node 20 or whatever)

* Check that the known collisions match our known list.
* @param {Array<CtcMessage>} fixedCollisions
*/
function checkKnownCollisions(fixedCollisions) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split this into a different function because otherwise the only way to test resolveMessageCollisions would be against all the strings collected from lighthouse (since all the known collisions are asserted to be there). If this file gets much more testing, it probably just needs to not interleave reading/writing disk and the parsing/string creation code

/** Description of a Lighthouse audit that tells the user *why* they should have accessible names for HTML elements. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
description: 'When an element doesn\'t have an accessible name, screen readers announce it with a generic name, making it unusable for users who rely on screen readers. [Learn how to name `tooltip` elements](https://dequeuniversity.com/rules/axe/4.4/aria-tooltip-name).',
/** Description of a Lighthouse audit that tells the user *why* they should have accessible names for HTML 'tooltip' elements. This is displayed after a user expands the section to see more. No character length limits. 'Learn how...' becomes link text to additional documentation. */
description: 'When a tooltip element doesn\'t have an accessible name, screen readers announce it with a generic name, making it unusable for users who rely on screen readers. [Learn how to name `tooltip` elements](https://dequeuniversity.com/rules/axe/4.4/aria-tooltip-name).',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mark tooltip/meter with backticks?

Copy link
Member Author

@brendankenny brendankenny Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took that from the axe docs (e.g. "Aria tooltip elements must have discernible text..."), though to be fair, their docs language selector has only one other language and that particular string stays in english :)

I kind of justified it in my head as it's an aria role, but also a description of the type of element, so it makes some sense to include a localized name. tooltip (and meter for aria-meter-name) are backticked later in the string 🤷

edit: I could make the second reference more explicitly the markup version, Learn how to name `role="tooltip" ` elements

return JSON.parse(JSON.stringify(input));
}

/** @return {Record<'first'|'second'|'third', CtcWithPlaceholders>} */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be really nice. I can't make it trigger and the PR doesn't include any jsdoc tests, so I assume it's a different enough parsing flow that it doesn't get picked up in any jsdoc equivalent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you motivated me: microsoft/TypeScript#51086 :)

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the exhaustive documentation and research into this. lgtm!

@connorjclark connorjclark merged commit ba425cd into main Oct 6, 2022
@connorjclark connorjclark deleted the string-collisions branch October 6, 2022 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants